#include<iostream.h>
#include"Thermtat.h"
#include"tstring.h"
//in this solution, the user merely uses the pre-set thermostat during its
//design stage. It doesn't make sense that the user defines the thresh-hold
//of the thermostat, since there are fixed standards about the "Comfort Zone".
//class implementation
//the Thermostat temp is set to 23 deg, and has a tolerance of 1 deg.
Thermostat::Thermostat()
{
tempSet=23;
delta=1;
switchMode=false;
}
//the switch is on for cold temperatures <=22, otherwise it's off
//for mild to hot temperatures.
void Thermostat::readTemp( double currenTemp)
{
//since the switch is set off by default for 23 deg and above. There is
//no need to check the switch state, since the sensor triggers it on or of
//for given temperatures
if(currenTemp<(tempSet-delta))
{
switchMode=true;
}
else if(currenTemp<(tempSet+delta))
{
switchMode=false;
}
}
//this fcn returns the state of the switch in 1 for true and 0 for false
bool Thermostat::switchState()
{
return switchMode;
}
//main program
int main()
{
String switchIt;
double sensorTemp=14;
Thermostat test;// a test object is created
cout<<endl;
cout<<" "<<" Room Tempertaure "<<'\t'<<" Switch Condition "<<endl;
cout<<" "<<" ________________ "<<'\t'<<" ________________ "<<endl<<endl;
//behaviour of the thermostat is studied from 14 to 32 degrees celsuis
while((sensorTemp>=14) && (sensorTemp<=32))
{
test.readTemp(sensorTemp);
if(test.switchState()==true)
{
switchIt="on";
}
else
{
switchIt="off";
}
cout<<" "<<sensorTemp<<'\t'<<'\t'<<'\t'<<'\t'<<switchIt<<endl;
sensorTemp++;
}
return 0;
}
/*
Run:
Room Tempertaure Switch Condition
________________ ________________
14 on
15 on
16 on
17 on
18 on
19 on
20 on
21 on
22 off
23 off
24 off
25 off
26 off
27 off
28 off
29 off
30 off
31 off
32 off
Press any key to continue
*/
|